package cn.jlearn.proxy.agent.handler.bs;

import cn.jlearn.proxy.agent.container.ForwardClient;
import cn.jlearn.proxy.common.body.TcpBody;
import cn.jlearn.proxy.common.handler.AbstractBsHandler;
import cn.jlearn.proxy.common.packet.BsPacket;
import cn.jlearn.proxy.common.packet.TcpPacket;
import org.tio.core.ChannelContext;
import org.tio.core.Tio;

/**
 * @author qianyingchao
 * @version 1.0
 * @date 2021/5/10 4:38 下午
 */
public class TcpReqHandler extends AbstractBsHandler<TcpBody> {

    @Override
    public Class<TcpBody> bodyClass() {
        return TcpBody.class;
    }

    @Override
    public void handler(BsPacket packet, TcpBody bsBody, ChannelContext channelContext) throws Exception {
        String bsId = bsBody.getBsId();
        TcpPacket tcpPacket = new TcpPacket(bsBody.getBytes());

        Tio.sendToBsId(ForwardClient.clientTioConfig, bsId, tcpPacket);
    }

}
